/**
 * Created by hasee on 2017/5/19.
 *
 */

var NIE_topBar = document.getElementsByClassName("NIE-topBar")[0];
var top_bar = document.getElementById("top_bar");
var content = document.getElementsByClassName("content")[0];
var topnav_li = document.getElementsByClassName("topnav_li");
var topbar_more = document.getElementsByClassName("topbar_more");
var tb1 = document.getElementById("tb1");
var tb2 = document.getElementById("tb2");
var ew = document.getElementById("ew");
var ewm1 = document.getElementById("ewm1");
var tm = topbar_more.children;
var tb = top_bar.children;
var wrap = document.getElementById("wrap");
var tt = document.getElementById("tt");
var dh = document.getElementById("dh");//����
var dh1 = document.getElementById("dh1");
var top_bar1 = document.getElementById("top_bar1");
var as = dh.children;
var lp = document.getElementById("lp");

$(function () {
    $("#small,#big").mouseover(function () {
        $("#big").css("display","block")
    }).mouseout(function () {
        $("#big").css("display","none")
    })
    $("#big").click(function () {
        $("#big").css("display","none")
    })
    $("#li1").mouseover(function () {
        $("#li1").css("background-image",'url("image/li1-1.png")')
    }).mouseout(function () {
        $("#li1").css("background-image",'url("image/li1.png")')
    })
    $("#li2").mouseover(function () {
        $("#li2").css("background-image",'url("image/li2-2.png")')
    }).mouseout(function () {
        $("#li2").css("background-image",'url("image/li2.png")')
    })
    $("#li3,#mulu").mouseover(function () {
        $("#li3").css("background-image",'url("image/li3-3.png")')
        $("#mulu").css("display","block")
    }).mouseout(function () {
        $("#li3").css("background-image",'url("image/li3.png")')
        $("#mulu").css("display","none")
    })

    $("em").mouseover(function(){
        $(this).css("background","rgb(243,243,243");
    });
    $("em").mouseout(function(){
        $(this).css("background","");
    })

    $(".btn-close").click(function(){
        $("#Jsider").stop();
        $("#Jsider").hide(500);
    });
    $("#Jdownloadbtn").click(function(){
        $("#Jsider").show(500);
    });


    $("#Jdownloadbtn").mouseover(function(){
        $("#Jdownloadbtn").fadeTo(500, 0.8)
    });
    $("#Jdownloadbtn").mouseout(function(){
        $("#Jdownloadbtn").fadeTo(500, 1)
    });




    $("#Jsider").show(500);
//        $(".logo").animate({"left":52},800);
    $(".logo").show(1200);




    $("#li7").mouseover(function(){
        $(".topbar_more").addClass("show");
        $("#tb1").addClass("show");
        $("#tb2").removeClass("show");
        $("#top_bar1").fadeTo(200, 0.9)
        $("#tb1").fadeTo(200, 1);
        $("#tb2").fadeTo(200, 0);
        $("#a1").fadeTo(200, 1);
        $("#a2").fadeTo(200, 0);

        $(".topbar_more").mouseleave(function(){
            $(".topbar_more").removeClass("show");
            $("#top_bar1").fadeTo(200, 0);
            $("#tb1").fadeTo(200, 0);
            $("#a1").fadeTo(200, 0);
        });
        $("#li8").mouseover(function(){
            $(".topbar_more").addClass("show");
            $("#tb2").addClass("show");
            $("#tb1").removeClass("show");
            $("#top_bar1").fadeTo(200, 0.9);
            $("#tb2").fadeTo(200, 1);
            $("#tb1").fadeTo(200, 0);
            $("#a1").fadeTo(200, 0);
            $("#a2").fadeTo(200, 1);
        });
        $(".topbar_more").mouseleave(function(){
            $(".topbar_more").removeClass("");
            $("#top_bar1").fadeTo(200, 0);
            $("#tb2").fadeTo(200, 0);
            $("#a2").fadeTo(200, 0);
        })
    });



    $("#cos").mouseover(function(){
        $("#cos").stop();
        $("#cos").animate({"marginTop":-17},300)
    });
    $("#cos").mouseout(function(){
        $("#cos").stop();
        $("#cos").animate({"marginTop":0},200)
    });
    $("#huihua").mouseover(function(){
        $("#huihua").stop();
        $("#huihua").animate({"marginTop":-17},300)
    });
    $("#huihua").mouseout(function(){
        $("#huihua").stop();
        $("#huihua").animate({"marginTop":0},200)
    });


    $("#baidu").mouseover(function(){
        $("#baidu").stop();
        $("#baidu").animate({"marginTop":-17},300)
    });
    $("#baidu").mouseout(function(){
        $("#baidu").stop();
        $("#baidu").animate({"marginTop":0},200)
    });
    $("#bbs").mouseover(function(){
        $("#bbs").stop();
        $("#bbs").animate({"marginTop":-17},300)
    });
    $("#bbs").mouseout(function(){
        $("#bbs").stop();
        $("#bbs").animate({"marginTop":0},200)
    });

    $("#share a").mouseover(function () {
        $(this).css("opacity","0.5")
    })
    $("#share a").mouseout(function () {
        $(this).css("opacity","1")
    })

    //$("#guild,a").mouseover(function () {
    //    $(this).css({"color":"white","text-decoration":"underline"})
    //})
    //$("#guild,a").mouseout(function () {
    //    $(this).css({"color":"#666","text-decoration":"none"})
    //})
});



var xx = document.getElementById("xx1");

var timer = setInterval(play, 500);
xx.onmouseover = function () {
    clearInterval(timer);
};
xx.onmouseout = function () {
    timer = setInterval(play, 500);
};

function play() {
    var leader = ul.offsetTop;
    var step = -5;
    if (leader > -125) {
        leader = leader + step;
        ul.style.top = leader + "px";
    } else {
        ul.style.top = 0;
    }
}




//��������Ŀ b
window.onscroll = function () {
    if (scroll().top > NIE_topBar.offsetHeight) {
        top_bar.className = "fixed";
        //topnav_li[4].className = "topnav_li ssl";
        //topnav_li[5].className = "topnav_li zjl";
        $(".logo").slideUp(500);
        animateLinear(top_bar,0.2,{"opacity":1});
        animateLinear(top_bar1,0.2,{"opacity":0.9});
        animateLinear(lp,0.2,{"opacity":1})
    } else {
        top_bar.className = "";
        //topnav_li[4].className = "topnav_li ssl hide";
        //topnav_li[5].className = "topnav_li zjl hide";
        $(".logo").slideDown(500);
        animateLinear(top_bar1,0.2,{"opacity":0});
        animateLinear(lp,0.2,{"opacity":0})
    }
};
//��������Ŀ e


bb();//��ά�� b
function bb() {
    animate1(ewm1, 160, function () {
        animate1(ewm1, 0, bb);
    });
};
//��ά�� e

//������ b
var xx=document.getElementById("xx")
x();
function x() {
    animate2(xx, -4,function () {
        animate2(xx, 8, x);
    });
};
//������ e

//���� b
for (var i = 0; i < as.length; i++) {
    var str = null;
    as[i].onmouseover = function () {
        str = this.className;
        this.className = this.className + " all-tit"
    };
    as[i].onmouseout = function () {
        this.className = str;
    };
}
//���� e





//�ֲ�ͼ1 b
var box1 = document.getElementById("box1");
var an = document.getElementById("an");
var ans = an.children;
var imgs = box1.children;
for (var i = 0; i < ans.length; i++) {
    ans[i].index = i;
    ans[i].onmouseover = function () {
        var target = -this.index * imgs[0].offsetWidth;
        for (var j = 0; j < ans.length; j++) {
            ans[j].className = "";
        }
        aa3(box1, target);
        this.className = "on"
    }
}
var pic1 = 0;
var square1 = 0;
setInterval(function () {
    if (pic1 === imgs.length - 1) {
        box1.style.left = 0 + "px";
        pic1 = 0;
    }
    pic1++;
    var target = -pic1 * imgs[0].offsetWidth;
    aa3(box1, target);
    if (square1 < ans.length - 1) {
        square1++;
    } else {
        square1 = 0;
    }
    for (var i = 0; i < ans.length; i++) {
        ans[i].className = "";
    }
    ans[square1].className = "on";
}, 6000);
//�ֲ�ͼ1 e


//�ֲ�ͼ2 b
var box2 = document.getElementById("box2");
var hd = document.getElementById("hd");
var imgss = document.getElementsByClassName("clone");
var hds = hd.children;
for (var i = 0; i < hds.length; i++) {
    hds[i].index = i;
    hds[i].onmouseover = function () {
        var target = -this.index * imgs[0].offsetWidth;
        for (var j = 0; j < hds.length; j++) {
            hds[j].className = "";
        }
        aa3(box2, target);
        this.className = "dot"
    }
}
var pic = 0;
var square = 0;
setInterval(function () {
    if (pic === imgs.length - 1) {
        box2.style.left = 0 + "px";
        pic = 0;
    }
    pic++;
    var target = -pic * imgs[0].offsetWidth;
    aa3(box2, target);
    if (square < hds.length - 1) {
        square++;
    } else {
        square = 0;
    }
    for (var i = 0; i < hds.length; i++) {
        hds[i].className = "";
    }
    hds[square].className = "dot on";
}, 4000);//�Զ�����
//�ֲ�ͼ2 e

//���汳�� b
var item = document.getElementsByClassName("news-list")[0];
var items=item.getElementsByClassName("item");
var ccs=item.getElementsByClassName("category $cname");
for (var i = 0; i < items.length; i++) {
    var str=null;
    items[i].onmouseover=function(){
        this.children[0].style.display="block";
        str=this.className
        this.className=this.className+" on";
        aa1(this.children[0],{"left":-18});
    };
    items[i].onmouseout=function(){
        this.children[0].style.display="none";
        this.className=str;
        aa1(this.children[0],{"left":0});
    }
}
//���汳�� e


//��ת b
var xl=document.getElementById("xl");
var xl1=document.getElementById("xl1");
var ems=document.getElementsByName("em");
xl1.onclick=function(){
    if(xl.className==="pager-list "){
        xl.className="pager-list show";
    }else{
        xl.className="pager-list ";
    }
};
//��ת e

//�л� b
var wb=document.getElementById("wb");
var wx=document.getElementById("wx");
var e1=document.getElementById("e1");
var e2=document.getElementById("e2");
wx.onmouseover=function(){
    wx.className="weixin-tit show";
    wb.className="weibo-tit";
    e1.className="show";
    e2.className="";
};
wb.onmouseover=function(){
    wb.className="weibo-tit show";
    wx.className="weixin-tit";
    e1.className="";
    e2.className="show";
};
//�л� e

//�����ת b
var xz=document.getElementById("xz");
xz.onmouseover=function(){
    xz.style.transform="rotate(180deg)"
};
xz.onmouseout=function(){
    xz.style.transform="rotate(-180deg)"
};
//�����ת e



function aa3(obj, target) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var leader = obj.offsetLeft;
        var step = 8;
        step = leader < target ? step : -step;//step��������
        if (Math.abs(leader - target) >= Math.abs(step)) {
            leader = leader + step;
            obj.style.left = leader + "px";
        } else {
            obj.style.left = target + "px";//�ֶ��ŵ��յ�
            clearInterval(obj.timer);
        }
    }, 15);
}
function getStyle(obj, attr) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(obj, null)[attr];
    } else {
        return obj.currentStyle[attr];
    }
}
function scroll() {
    return {
        top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0,
        left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0
    };
}
//���������ƶ�
function animate1(obj, target, fn) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var leader = obj.offsetTop;
        var step = 1;
        step = leader < target ? step : -step;//step��������
        if (Math.abs(leader - target) >= Math.abs(step)) {
            leader = leader + step;
            obj.style.top = leader + "px";
        } else {
            obj.style.top = target + "px";//�ֶ��ŵ��յ�
            clearInterval(obj.timer);
            if (fn) {
                fn()
            }
        }
    }, 15);
}
function animate2(obj, target, fn) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var leader = obj.offsetTop;
        var step = 1;
        step = leader < target ? step : -step;//step��������
        if (Math.abs(leader - target) >= Math.abs(step)) {
            leader = leader + step;
            obj.style.top = leader + "px";
        } else {
            obj.style.top = target + "px";//�ֶ��ŵ��յ�
            clearInterval(obj.timer);
            if (fn) {
                fn()
            }
        }
    }, 15);
}
//��������
function aa2(obj, target) {
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        var leader = obj.offsetLeft;
        var step = (target - leader) / 10;
        step = step > 0 ? Math.ceil(step) : Math.floor(step);
        leader = leader + step;
        obj.style.left = leader + "px";
        if (leader === target) {
            clearInterval(obj.timer);
        }
    }, 15);
}
//�����ƶ�
function aa1(obj, json, fn) {
    clearInterval(obj.a);
    obj.a = setInterval(function () {
        var flag = true;
        for (var k in json) {
            if (k === "opacity") {
                var leader = getStyle(obj, k) * 100;
                var target = json[k] * 100;
                var step = (target - leader) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                leader = leader + step;
                obj.style[k] = leader / 100;
            } else if (k === "zIndex") {
                obj.style.zIndex = json[k];
            } else {
                var leader = parseInt(getStyle(obj, k)) || 0;
                var target = json[k]
                var step = (target - leader) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                leader = leader + step;
                obj.style[k] = leader + "px";
            }

            if (leader !== target) {
                flag = false;
            }
        }
        if (flag) {
            clearInterval(obj.a);
            if (fn) {
                fn();
            }
        }
    }, 20)
}





